# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=nerdctl
pkgver=1.7.6
pkgrel=0
pkgdesc="Docker-compatible CLI for containerd"
url="https://github.com/containerd/nerdctl/"
arch="all"
license="Apache-2.0"
depends="ca-certificates containerd cni-plugins iptables"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/containerd/nerdctl/archive/refs/tags/v$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -v \
		-ldflags="
		-X github.com/containerd/nerdctl/pkg/version.Version=$pkgver \
		-X github.com/containerd/nerdctl/pkg/version.Revision=AlpineLinux \
		" \
		./cmd/nerdctl

	for shell in bash fish zsh; do
		./nerdctl completion $shell > nerdctl.$shell
	done
}

check() {
	# Tests inside cmd/nerdctl module require 'nerdctl' binary to be inside PATH
	# TestGet test fails to read /run/systemd/resolve/resolv.conf file (we're not using systemd here)
	# shellcheck disable=2046
	go test -skip TestGet $(go list ./... | grep -v "/cmd/nerdctl")
}

package() {
	install -Dm755 nerdctl -t "$pkgdir"/usr/bin/
	install -Dm644 docs/*.md -t "$pkgdir"/usr/share/doc/$pkgname/

	install -Dm644 nerdctl.bash \
		"$pkgdir"/usr/share/bash-completion/completions/nerdctl
	install -Dm644 nerdctl.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/nerdctl.fish
	install -Dm644 nerdctl.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_nerdctl
}

sha512sums="
8fd8a393c25206b7213fa7a95f4d6c76ed68aad82cfc6c8968d134e7d31304f4b7c20e6fa8b6d825c5398ccf5f08f3af94a3e3f7b30ebdf2ac7aa2066120bc50  nerdctl-1.7.6.tar.gz
"
